package com.carboy.launch.activity.column;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.location.GpsStatus;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.os.SystemProperties;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnSystemUiVisibilityChangeListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.carboy.launch.BaseApplication;
import com.carboy.launch.IflyTTS;
import com.carboy.launch.R;
import com.carboy.launch.TtsManager;
import com.carboy.launch.activity.setting.SettingMainActivity;
import com.carboy.launch.bean.ConfigInfo;
import com.carboy.launch.bean.Version;
import com.carboy.launch.update.UpdateTimeThread;
import com.carboy.launch.utils.Constants;
import com.carboy.launch.utils.DateUtils;
import com.carboy.launch.utils.JwdLog;
import com.carboy.launch.utils.SharedPreferencesUtils;
import com.carboy.launch.utils.StringUtils;
import com.carboy.launch.utils.Tool;
import com.carboy.launch.widgets.CustomToast;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.InitListener;
import com.jwd.clouddog.config.JwdConstant;
import com.jwd.clouddog.config.ServerIntent;
import com.jwd.clouddog.tools.JwdServerDateMethod;
import com.rk.applist.AppListActivity;

/**
 * 主栏目Activity
 */
public class ColumnMainActivity extends BaseActivity implements OnClickListener {

	private long cloudtime = System.currentTimeMillis();
	private long cloudStatetime = System.currentTimeMillis();
	// ========================定位================================
	
	private TextView is_temperature_tv;
	// 当前上下文
	private Context mContext;
	// ===================== 控件View ============================
	private RadioGroup radioGroup;
	/** 指示图按钮数组 */
	private RadioButton[] radioButtons_point;// 不需要在布局文件定义，会自动添加
	private ArrayList<View> viewList = null;
	private ViewPager viewPager;
	private TextView tv_time, tv_data, tv_bst;

	private ImageView is_weather_igview, isupdata; // 天气状态
	private Button acm_navigation_btn; // 导航按钮
	private Button acm_dwarning_btn; // 电子预警按钮
	private Button acm_weme_btn; // 应用按钮
	private Button acm_grapher_btn; // 记录仪按钮
	private Button acm_setting_btn; // 设置按钮
	private LinearLayout acm_time_btn; // 时间
	private Button acm_about_btn; // 关于
	private Button acm_GPSCam_btn; // 搜星定位
	private Button acm_music_btn; // 音乐
	private Button acm_video_btn; // 视频
	private Button acm_bluetooth_btn; // 蓝牙
	private Button acm_FM_btn; // FM
	private Button acm_file_btn; // 文件

	private HomeKeyBroadcastReceiver mHomeKeyBroadcastReceiver;
	// handler常量
	public static final int HANDLER_UPDATATIME = 1;// 更新时间
	private final int BASE_SYS_UI_VISIBILITY =
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            //| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_FULLSCREEN;

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_column_main);
		getWindow().getDecorView().setSystemUiVisibility(BASE_SYS_UI_VISIBILITY );
		getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                new OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                    	getWindow().getDecorView().setSystemUiVisibility(BASE_SYS_UI_VISIBILITY );
                    }
                });
		mContext = ColumnMainActivity.this;
		initViews();
		initStatusBar();
		initListeners();

		if (mHomeKeyBroadcastReceiver == null) {
			mHomeKeyBroadcastReceiver = new HomeKeyBroadcastReceiver();
			IntentFilter intentFilter = new IntentFilter();
			intentFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
			intentFilter
					.addAction(ServerIntent.ACTION_SERVER_CONNECT_STATE_DATA);
			intentFilter.addAction(ServerIntent.ACTION_SERVER_RUNNING_STATE);
			intentFilter
					.addAction("android.intent.action.SYSTEMKEY_MUTE_CANCEL");
			this.registerReceiver(mHomeKeyBroadcastReceiver, intentFilter);
			cardogHandler.sendEmptyMessageDelayed(1, 60000);
			cardogHandler.sendEmptyMessageDelayed(2, 60000);
		}
		setSBarTime();
		SystemProperties.set("sys.car.reverse", "2");
	}

	Timer updateTimer = null;
	TimerTask mTimerTask = null;

	/**
	 * 
	 * @author James
	 * @Description 从网络获取时间
	 */
	public void updateTime() {
		// 先停止系统时间
		if (sBarTimer != null) {
			sBarTimer.cancel();
			sBarTimer.purge();
			sBarTimer = null;
		}

		updateTimer = new Timer();
		mTimerTask = new TimerTask() {

			@Override
			public void run() {
				new UpdateTimeThread(mHandler).run();
			}
		};
		updateTimer.schedule(mTimerTask, 0, 30000);// 30秒获取一次
	}

	/**
	 * 初始化控件
	 */
	private void initViews() {
		is_temperature_tv = (TextView) this
				.findViewById(R.id.is_temperature_tv); // 温度
		isupdata = (ImageView) findViewById(R.id.is_backrecord_igview);
		viewPager = (ViewPager) findViewById(R.id.pager);
		radioGroup = (RadioGroup) findViewById(R.id.raidoGroup);
		LayoutInflater lf = getLayoutInflater().from(this);
		View view1 = lf.inflate(R.layout.mainpage1, null);
		View view2 = lf.inflate(R.layout.mainpage2, null);
		View view3 = lf.inflate(R.layout.mainpage3, null);
		View view4 = lf.inflate(R.layout.mainpage4, null);
		viewList = new ArrayList();// 将要分页显示的View装入数组中
		viewList.add(view1);
		viewList.add(view2);
		viewList.add(view3);
		viewList.add(view4);
		MainPageAdapter adapter = new MainPageAdapter(viewList);
		viewPager.setAdapter(adapter);

		/* for循环，初始化所有的指示图按钮，并添加到指示图的RadioGroup中 */
		int margin_num = Tool.dp2px(ColumnMainActivity.this, 5);
		for (int i = 0; i < 4; i++) {
			RadioButton btn = new RadioButton(ColumnMainActivity.this);
			btn.setId(i);// 设置指示图按钮ID
			btn.setButtonDrawable(R.drawable.mainpager_radio);// 设置背景图
			RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(
					getResources().getDrawable(R.drawable.point_white_n)
							.getMinimumWidth(), getResources().getDrawable(
							R.drawable.point_white_n).getMinimumHeight());
			layoutParams.setMargins(margin_num, 0, margin_num, 0);
			btn.setLayoutParams(layoutParams);
			btn.setClickable(false);// 设置指示图按钮不能点击
			radioGroup.addView(btn);// 把已经初始化的指示图动态添加到指示图的RadioGroup中
		}
		radioGroup.check(0);

		viewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				radioGroup.check(arg0);
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});

		tv_time = (TextView) findViewById(R.id.main_time);
		tv_data = (TextView) findViewById(R.id.main_data);
		tv_bst = (TextView) findViewById(R.id.baishitong);

		acm_dwarning_btn = (Button) view1.findViewById(R.id.acm_carboy_btn); // 电子预警按钮
		acm_dwarning_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				// 车宝云
				try {
					Intent intent = mContext.getPackageManager()
							.getLaunchIntentForPackage("com.jwd.clouddog.show");
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(intent);
				} catch (Exception e) {
					// 出现异常,表示找不到APP,报NULL,或者出现其他情况
					CustomToast
							.showToast(mContext, R.string.intnet_apply_error);
				}

			}
		});
		acm_navigation_btn = (Button) view1
				.findViewById(R.id.acm_navigation_btn); // 导航按钮
		acm_grapher_btn = (Button) view1.findViewById(R.id.acm_grapher_btn); // 记录仪按钮

		acm_setting_btn = (Button) view2.findViewById(R.id.acm_setting_btn); // 设置按钮
		acm_bluetooth_btn = (Button) view2.findViewById(R.id.acm_bluetooth_btn); // 蓝牙
		acm_FM_btn = (Button) view2.findViewById(R.id.acm_FM_btn); // FM

		acm_music_btn = (Button) view3.findViewById(R.id.acm_music_btn); // 音乐
		acm_video_btn = (Button) view3.findViewById(R.id.acm_video_btn); // 视频
		acm_file_btn = (Button) view3.findViewById(R.id.acm_file_btn);// 文件

		acm_time_btn = (LinearLayout) findViewById(R.id.acm_time_btn); // 时间

		acm_weme_btn = (Button) view4.findViewById(R.id.acm_weme_btn); // 微密
		acm_about_btn = (Button) view4.findViewById(R.id.acm_about_btn); // 关于
		acm_GPSCam_btn = (Button) view4.findViewById(R.id.acm_GPSCam_btn); // 搜星定位
		is_weather_igview = (ImageView) this
				.findViewById(R.id.is_weather_igview); // 云服务器联机状态标记，正常显示，没连接和连接不成功不显示

	}

	/**
	 * 初始化事件
	 */
	private void initListeners() {

		acm_navigation_btn.setOnClickListener(this); // 导航按钮
		acm_file_btn.setOnClickListener(this);

		acm_weme_btn.setOnClickListener(this); // 应用按钮
		acm_grapher_btn.setOnClickListener(this); // 记录仪按钮
		acm_setting_btn.setOnClickListener(this); // 设置按钮

		acm_about_btn.setOnClickListener(this); // 关于
		acm_time_btn.setOnClickListener(this); // 时间

		acm_GPSCam_btn.setOnClickListener(this); // 搜星定位
		acm_music_btn.setOnClickListener(this); // 音乐
		acm_video_btn.setOnClickListener(this); // 视频
		acm_bluetooth_btn.setOnClickListener(this); // 蓝牙
		acm_FM_btn.setOnClickListener(this); // FM
		tv_bst.setOnClickListener(this);
	}
	/**
	 * 点击事件
	 */
	@Override
	public void onClick(View v) {
		// 跳转对象
		switch (v.getId()) {
		case R.id.acm_navigation_btn:
			// 导航按钮
			try {
				Intent intent3 = new Intent(Intent.ACTION_MAIN);
				intent3.addCategory(Intent.CATEGORY_LAUNCHER);
				ComponentName comp = new ComponentName("com.jwd.clouddog.show",
						"com.jwd.clouddog.show.NaviActivity");
				intent3.setComponent(comp);
				intent3.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(intent3);
			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}

			break;

		case R.id.acm_file_btn:
			// 文件管理
			try {
				Tool.startApp(mContext,"com.android.rk", "com.android.rk.RockExplorer");

			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}

			break;
		case R.id.acm_time_btn:
			// 时间
			BaseApplication.playClickVoice(mContext);
			TtsManager.getInstance(getApplicationContext()).playText2(
					getResources().getString(R.string.play_text_time_now) + tv_time.getText());

			break;
		case R.id.acm_grapher_btn:
			Tool.startApp(mContext, "com.rk.carrecorder",
					"com.rk.carrecorder.CameraActivity");
			break;
		case R.id.acm_setting_btn:
			// 设置按钮
			Intent si = new Intent(ColumnMainActivity.this,
					SettingMainActivity.class);
			ColumnMainActivity.this.startActivity(si);

			break;
		case R.id.acm_weme_btn:
			// 微密
			try {
				Intent intent = new Intent(ColumnMainActivity.this, AppListActivity.class);
				ColumnMainActivity.this.startActivity(intent);
			} catch (Exception e2) {
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}
			break;
		case R.id.acm_about_btn:
			// 关于
			try {
				// 通过包名打开app
				Tool.startApp(mContext, "com.jwd.jwdabout",
						"com.jwd.jwdabout.activity.AboutActivity");
			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}
			break;
		case R.id.acm_FM_btn:
			// FM
			try {
				// 通过包名打开app
				Tool.startApp(mContext, "com.rk.fm",
						"com.rk.fm.FmActivity");
			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}
			break;
		case R.id.acm_GPSCam_btn:
			// 搜星定位
			try {
//				Tool.startApp(mContext, "com.autonavi.xmgd.navigator",
//						"com.autonavi.xmgd.navigator.Warn");
//				Tool.startApp(mContext, "com.chartcross.gpstestplus",
//						"com.chartcross.gpstestplus.GPSTestPlus");
              Tool.startApp(mContext, "com.android.yecon.gpstest",
              "com.android.yecon.gpstest.GPSTest");
			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}
			break;
		case R.id.acm_music_btn:
			// 音乐
//			boolean isExist = Tool.isPackageExists(mContext,
//					"com.jwd.carboy.music");
//			if (!isExist) {
//				TtsManager.getInstance(mContext).playText(getResources().getString(R.string.play_text_music_not_install));
//				return;
//			}
//			try {
//				Tool.startApp(mContext, "com.jwd.carboy.music",
//						"com.jwd.carboy.music.activity.MusicMainActivity");
//			} catch (Exception e1) {
//				e1.printStackTrace();
//				CustomToast.showToast(mContext, getResources().getString(R.string.play_text_music_not_install));
//			}
            try {
              Tool.startApp(mContext, "cn.kuwo.kwmusiccar",
                      "cn.kuwo.kwmusiccar.MainActivity");
            } catch (Exception e1) {
                e1.printStackTrace();
                CustomToast.showToast(mContext, getResources().getString(R.string.play_text_music_not_install));
            }

			break;
		case R.id.acm_video_btn:
			// 视频
			try {
				Tool.startApp(mContext, "android.rk.RockVideoPlayer",
						"android.rk.RockVideoPlayer.RockVideoPlayer");
			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}
			break;
		case R.id.acm_bluetooth_btn:
			// 蓝牙
			try {
				Tool.startApp(mContext, "com.AnywheeBt",
						"com.AnywheeBt.MainActivity");
				break;
			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}

			break;
		case R.id.baishitong:
			// 启动语音
			try {
				Intent intent = new Intent(Intent.ACTION_MAIN);
				intent.addCategory(Intent.CATEGORY_LAUNCHER);
				ComponentName comp = new ComponentName("com.jwd.jwdvoicetool",
						"com.jwd.jwdvoicetool.JwdVoiceActivity");
				intent.setComponent(comp);
				intent.putExtra("isBSTMode", true);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

				startActivity(intent);
			} catch (Exception e) {
				// 出现异常,表示找不到APP,报NULL,或者出现其他情况
				CustomToast.showToast(mContext, R.string.intnet_apply_error);
			}

			break;
		}
	}

	/**
	 * 重写返回键
	 */
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {

			viewPager.setCurrentItem(0);

			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onRestart() {
		super.onRestart();
	}

	@Override
	protected void onStop() {
		super.onStop();

	}

	@Override
	protected void onPause() {
		super.onPause();

	}

	@Override
	protected void onResume() {
		// 关闭微密语音
		Intent offScreen = new Intent(
				"android.intent.action.ACTION_MT_VOICE_STOP");
		sendBroadcast(offScreen);
		super.onResume();

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();

		cardogHandler.removeMessages(1);
		cardogHandler.removeMessages(2);
		cardogHandler.removeMessages(3);
		

		if (mHomeKeyBroadcastReceiver != null) {
			this.unregisterReceiver(mHomeKeyBroadcastReceiver);
		}
		if (updateTimer != null) {
			updateTimer.cancel();
			updateTimer.purge();
			updateTimer = null;
		}
		if (sBarTimer != null) {
			sBarTimer.cancel();
			sBarTimer.purge();
			sBarTimer = null;
		}
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		// Activity被回收,则保存数据
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
		// 切屏触发
	}

	private class MainPageAdapter extends PagerAdapter {

		private List<View> views;

		public MainPageAdapter(List<View> views) {
			this.views = views;
		}

		@Override
		public int getCount() {
			return views.size();
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == arg1;
		}

		public void destroyItem(ViewGroup container, int position, Object object) {
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			try {
				((ViewPager) arg0).addView(views.get(arg1));
			} catch (Exception e) {
			}
			return views.get(arg1);
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public int getItemPosition(Object object) {
			// TODO Auto-generated method stub
			return POSITION_NONE;
		}

	}

	/** 设置定时器参数 */
	private void setSBarTime() {
		sBarTimer = new Timer(); // 每次重新new 防止被取消
		// 重新生成定时器 防止出现TimerTask is scheduled already 所以同一个定时器任务只能被放置一次
		sBarTask = new TimerTask() {
			@Override
			public void run() {
				// 需要做的事:发送消息
				Message message = new Message();
				message.what = 1;
				sBarHandler.sendMessage(message);
			}
		};
		// 5秒获取一次
		sBarTimer.schedule(sBarTask, 0, 5000); // 开启定时器
	}

	Timer sBarTimer; // 定时器
	TimerTask sBarTask; // 定时器任务栈+

	Handler sBarHandler = new Handler() {
		public void handleMessage(Message msg) {
			if (msg.what == 1) {
				try {
					settime();
					//
				} catch (Exception e) {
				}
			}
			super.handleMessage(msg);
		}
	};

	private void settime() {
		// TODO Auto-generated method stub
		tv_time.setText(DateUtils.getDateNow("HH:mm"));
		tv_data.setText(DateUtils.getDateNow("yyyy/MM/dd/EEEE"));
	};

	private Handler mHandler = new Handler() {

		public void handleMessage(Message msg) {
			Bundle mBundle = msg.getData();
			switch (msg.what) {
			case 1:
				long time = mBundle.getLong("time");
				// 说明获取网络数据失败，不在获取
				if (time == 0) {
					setSBarTime();
					if (updateTimer != null) {
						updateTimer.cancel();
						updateTimer.purge();
						updateTimer = null;
					}
					return;
				}
				Date date = new Date(time); // 转换为标准时间对象
				String netnyr = DateUtils.getNetDate(date, "yyyy/MM/dd/EEEE");// 网络年月日，作对比
				String nettime = DateUtils.getNetDate(date, "HH:mm");// 网络时间				
				String systemday = DateUtils.getDateNow("yyyy/MM/dd/EEEE");// 获取系统日期，和网络获取对比
				if (!TextUtils.isEmpty(systemday)) {
					// 网络日期==系统日期，不在取联网获取
					if (systemday.equals(netnyr)) {
						setSBarTime();
						if (updateTimer != null) {
							updateTimer.cancel();
							updateTimer.purge();
							updateTimer = null;
						}
					} else {
						if (!TextUtils.isEmpty(netnyr)
								&& !TextUtils.isEmpty(nettime)) {
							tv_time.setText(DateUtils.getDateNow(nettime));
							tv_data.setText(DateUtils.getDateNow(netnyr));
						}

					}
				}

				break;

			default:
				break;
			}
		};
	};

	public class HomeKeyBroadcastReceiver extends BroadcastReceiver {
		private final String SYSTEM_REASON = "reason";
		// Home键
		private final String SYSTEM_HOME_KEY = "homekey";
		// 最近使用的应用键
		private final String SYSTEM_RECENT_APPS = "recentapps";

		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
				String systemReason = intent.getStringExtra(SYSTEM_REASON);
				if (systemReason != null) {
					if (systemReason.equals(SYSTEM_HOME_KEY)) {
						viewPager.setCurrentItem(0);
					}
				}
			} else if (action.equals(ServerIntent.ACTION_SERVER_RUNNING_STATE)) {

				cardogHandler.removeMessages(1);
				cardogHandler.sendEmptyMessageDelayed(1, 60000);
			} else if (action
					.equals(ServerIntent.ACTION_SERVER_CONNECT_STATE_DATA)) {
				// 接收连接状态
				boolean connectState = intent.getBooleanExtra(
						JwdConstant.SERVER_CONNECT_STATE, false);
				com.carboy.launch.utils.Constants.clouddogConected = connectState;
				cardogHandler.removeMessages(3);
				cardogHandler.sendEmptyMessageDelayed(3, 30000);
				if (connectState) {

					com.carboy.launch.utils.Constants.isfalseconnectfail = true;
					cardogHandler.removeMessages(2);
				} else {
					if (com.carboy.launch.utils.Constants.isfalseconnectfail) {
						com.carboy.launch.utils.Constants.isfalseconnectfail = false;
						cardogHandler.removeMessages(2);
						cardogHandler.sendEmptyMessageDelayed(2, 60000);
					}

				}
			
			} 
		}

	}

	Handler cardogHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				if (Tool.isRunBackground(mContext, "com.jwd.clouddog.service")) {
					cloudtime = System.currentTimeMillis();
					cloudStatetime = System.currentTimeMillis();
					Tool.forceCloseApp(mContext, "com.jwd.clouddog.service");
					com.carboy.launch.utils.Constants.isfalseconnectfail = true;
					is_weather_igview.setVisibility(View.GONE);
				}
				break;
			case 2:
				if (Tool.isRunBackground(mContext, "com.jwd.clouddog.service")) {
					cloudtime = System.currentTimeMillis();
					cloudStatetime = System.currentTimeMillis();
					Tool.forceCloseApp(mContext, "com.jwd.clouddog.service");
					com.carboy.launch.utils.Constants.isfalseconnectfail = true;
					is_weather_igview.setVisibility(View.GONE);
				}
				break;
			case 3:
				is_weather_igview.setVisibility(View.GONE);
				break;
			default:
				break;
			}

		};
	};

	Handler mandler = null;
	/**
	 * 
	 * @author James
	 * @Description 检测关于app运行
	 */
	@SuppressLint("HandlerLeak")
	public void checkAboutService() {
		mandler = new Handler() {
			public void handleMessage(Message msg) {
				int what = msg.what;
				switch (what) {
				case 1:
					boolean isgyServiceRun = Tool.isServiceWorked(mContext,"com.jwd.jwdabout.service.AboutService");
					if (!isgyServiceRun) {
						Intent mIntent = new Intent("com.carboy.action.START.GUANYU.SERVICE");
						sendBroadcast(mIntent);
					}
					mandler.sendEmptyMessageDelayed(1, 5000);
					break;
				default:
					break;
				}
			};
		};
		// 检测关于服务是否在运行
		mandler.sendEmptyMessageDelayed(1, 10000);
	}
}